package com.wish.system.controller;


import com.wish.system.api.RemoteMessageService;
import com.wish.system.config.MessageConfig;
import com.zhenzi.sms.ZhenziSmsClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;

/**
 * @Auther: dingshiyu
 * @Date: 2022/5/25 17:07
 * @Description: 短信发送
 */
@RestController
@RequestMapping("message")
@Slf4j
public class MessageController {


    @Resource
    MessageConfig messageConfig;

    @Resource
    RemoteMessageService remoteMessageService;

    @RequestMapping("testMessage")
    public boolean testMessage(){
        boolean send = remoteMessageService.send("15661876409", "9436");
        return  send;
    }


    @RequestMapping("send")
    public boolean send(@RequestParam(value = "telephone") String telephone) {
        Random random = new Random();
        String code = "";
        for (int i = 0; i < 6; i++) {
            code += random.nextInt(10);
        }
        System.out.println(code);
//        // 使用自己的 AppId 和 AppSecret
//        ZhenziSmsClient client = new ZhenziSmsClient(messageConfig.getApiUrl(), messageConfig.getAppId(), messageConfig.getAppSecret());
//        Map<String, Object> params = new HashMap<>();
//        params.put("number", phoneNumber);
//        // 修改为自己的templateId
//        params.put("templateId", templateId);
//        String[] templateParams = new String[1];
//        templateParams[0] = code;
//        params.put("templateParams", templateParams);
//        try {
//            String result = client.send(params);
//            System.out.println(result);
//        } catch (Exception e) {
//            e.printStackTrace();
//        }

        return true;
    }


}

